<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_Etablissement extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(3)
     *
     * @var int
     */
    protected $_IdEtab;

    /**
     * Database var type varchar(150)
     *
     * @var string
     */
    protected $_NomEtab;

    /**
     * Database var type varchar(200)
     *
     * @var string
     */
    protected $_AdresseEtab;

    /**
     * Database var type varchar(40)
     *
     * @var string
     */
    protected $_EmailEtab;

    /**
     * Database var type varchar(40)
     *
     * @var string
     */
    protected $_SiteWebEtab;

    /**
     * Database var type int(3)
     *
     * @var int
     */
    protected $_UniversiteIdUniv;


    /**
     * Parent relation fk_etablissement_universite
     *
     * @var Application_Model_Universite
     */
    protected $_Universite;


    /**
     * Dependent relation fk_participant_etablissement1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Participant
     */
    protected $_Participant;

    /**
     * Dependent relation fk_salle_etablissement1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Salle
     */
    protected $_Salle;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'id_etab'=>'IdEtab',
            'nom_etab'=>'NomEtab',
            'adresse_etab'=>'AdresseEtab',
            'email_etab'=>'EmailEtab',
            'site_web_etab'=>'SiteWebEtab',
            'universite_id_univ'=>'UniversiteIdUniv',
        ));

        $this->setParentList(array(
            'FkEtablissementUniversite'=> array(
                    'property' => 'Universite',
                    'table_name' => 'Universite',
                ),
        ));

        $this->setDependentList(array(
            'FkParticipantEtablissement1' => array(
                    'property' => 'Participant',
                    'table_name' => 'Participant',
                ),
            'FkSalleEtablissement1' => array(
                    'property' => 'Salle',
                    'table_name' => 'Salle',
                ),
        ));
    }

    /**
     * Sets column id_etab
     *
     * @param int $data
     * @return Application_Model_Etablissement
     */
    public function setIdEtab($data)
    {
        $this->_IdEtab = $data;
        return $this;
    }

    /**
     * Gets column id_etab
     *
     * @return int
     */
    public function getIdEtab()
    {
        return $this->_IdEtab;
    }

    /**
     * Sets column nom_etab
     *
     * @param string $data
     * @return Application_Model_Etablissement
     */
    public function setNomEtab($data)
    {
        $this->_NomEtab = $data;
        return $this;
    }

    /**
     * Gets column nom_etab
     *
     * @return string
     */
    public function getNomEtab()
    {
        return $this->_NomEtab;
    }

    /**
     * Sets column adresse_etab
     *
     * @param string $data
     * @return Application_Model_Etablissement
     */
    public function setAdresseEtab($data)
    {
        $this->_AdresseEtab = $data;
        return $this;
    }

    /**
     * Gets column adresse_etab
     *
     * @return string
     */
    public function getAdresseEtab()
    {
        return $this->_AdresseEtab;
    }

    /**
     * Sets column email_etab
     *
     * @param string $data
     * @return Application_Model_Etablissement
     */
    public function setEmailEtab($data)
    {
        $this->_EmailEtab = $data;
        return $this;
    }

    /**
     * Gets column email_etab
     *
     * @return string
     */
    public function getEmailEtab()
    {
        return $this->_EmailEtab;
    }

    /**
     * Sets column site_web_etab
     *
     * @param string $data
     * @return Application_Model_Etablissement
     */
    public function setSiteWebEtab($data)
    {
        $this->_SiteWebEtab = $data;
        return $this;
    }

    /**
     * Gets column site_web_etab
     *
     * @return string
     */
    public function getSiteWebEtab()
    {
        return $this->_SiteWebEtab;
    }

    /**
     * Sets column universite_id_univ
     *
     * @param int $data
     * @return Application_Model_Etablissement
     */
    public function setUniversiteIdUniv($data)
    {
        $this->_UniversiteIdUniv = $data;
        return $this;
    }

    /**
     * Gets column universite_id_univ
     *
     * @return int
     */
    public function getUniversiteIdUniv()
    {
        return $this->_UniversiteIdUniv;
    }

    /**
     * Sets parent relation UniversiteIdUniv
     *
     * @param Application_Model_Universite $data
     * @return Application_Model_Etablissement
     */
    public function setUniversite(Application_Model_Universite $data)
    {
        $this->_Universite = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id_univ'];
        }

        $this->setUniversiteIdUniv($primary_key);

        return $this;
    }

    /**
     * Gets parent UniversiteIdUniv
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Universite
     */
    public function getUniversite($load = true)
    {
        if ($this->_Universite === null && $load) {
            $this->getMapper()->loadRelated('FkEtablissementUniversite', $this);
        }

        return $this->_Universite;
    }

    /**
     * Sets dependent relations fk_participant_etablissement1
     *
     * @param array $data An array of Application_Model_Participant
     * @return Application_Model_Etablissement
     */
    public function setParticipant(array $data)
    {
        $this->_Participant = array();

        foreach ($data as $object) {
            $this->addParticipant($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_participant_etablissement1
     *
     * @param Application_Model_Participant $data
     * @return Application_Model_Etablissement
     */
    public function addParticipant(Application_Model_Participant $data)
    {
        $this->_Participant[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_participant_etablissement1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Participant
     */
    public function getParticipant($load = true)
    {
        if ($this->_Participant === null && $load) {
            $this->getMapper()->loadRelated('FkParticipantEtablissement1', $this);
        }

        return $this->_Participant;
    }

    /**
     * Sets dependent relations fk_salle_etablissement1
     *
     * @param array $data An array of Application_Model_Salle
     * @return Application_Model_Etablissement
     */
    public function setSalle(array $data)
    {
        $this->_Salle = array();

        foreach ($data as $object) {
            $this->addSalle($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_salle_etablissement1
     *
     * @param Application_Model_Salle $data
     * @return Application_Model_Etablissement
     */
    public function addSalle(Application_Model_Salle $data)
    {
        $this->_Salle[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_salle_etablissement1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Salle
     */
    public function getSalle($load = true)
    {
        if ($this->_Salle === null && $load) {
            $this->getMapper()->loadRelated('FkSalleEtablissement1', $this);
        }

        return $this->_Salle;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Etablissement
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Etablissement());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Etablissement::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdEtab() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('id_etab = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdEtab()));
    }
}
